<!-- 库存汇总查询 - 综合表单页面 -->
<template>
  <div class="page-container">
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
      <!-- <template v-slot:action-right>
        <el-upload v-auth="'oms_stock_head_query_import'" action="" :show-file-list="false" style="display: inline;"
          :http-request="uploadFile">
          <el-button slot="trigger" size="mini" type="primary">{{ $tt('label_import_excel') }}</el-button>
        </el-upload>
      </template> -->
    </ex_super_table_page>

    <el-dialog :title="`[${$tt('label_stock_detail')}] ` + chooseRow.skuName + ' - ' + chooseRow.skuNameEn"
      :visible.sync="dialogVisible" width="1100px">
      <ex_super_table class="el-table-nowwarp" ref="resourceDownloadGridPanelEl"
        :url="'/oms-api/stock/OmsStockQueryRpc/stockContainerQuery.json?skuId=' + chooseRow.skuId + '&warehouseId=' + chooseRow.warehouseId"
        :attrs="{ autoPage: true, autoLoad: true }" height="400" v-bind="tableOption">
      </ex_super_table>
      <span slot="footer" class="dialog_footer">
        <el-button @click="dialogVisible = false">{{ $tt('label_close') }}</el-button>
      </span>
    </el-dialog>


  </div>
</template>
<script>
import { mapState } from "vuex";

import business_function from "@/common/business_function"

export default {
  title: 'title_stock_head_query',
  components: {},
  data() {


    return {
      selection: [],
      dialogVisible: false,
      chooseRow: {},

      option: {
        search: {
          model: [
            { label: "label_customer", key: "customerId", type: 'common_customer_choose', },
            { label: "label_sku", key: "skuId", type: 'sku_selec_input', },
            {
              label: "label_warehouse", key: "warehouseId", type: 'base_warehouse_select',
            },
            { label: "label_quantity_type", key: "qtyType", type: 'input', },

            { label: "label_quantity_range", key: "qty1", type: 'input', },
            { label: "", key: "qty2", type: 'input', }

          ],
        },
        actionExtra: [
          {
            label: 'label_export', auth: 'oms_stock_head_query_export', click: this.exportExcel
          },
          {
            label: 'label_download_excel_import_temp',
            auth: 'oms_stock_head_query_import',
            click: this.downloadImportTemp
          },
          {
            auth: 'oms_stock_head_query_import',
            render: (h) => (<button_select_file onInput={files => this.uploadFile(files)} >
              {this.$tt('label_import')}
              <i class="el-icon-upload2 el-icon--right"></i>
            </button_select_file>),
          },
        ],
        table: {
          url: "/oms-api/stock/OmsStockQueryRpc/stockHeadQuery.json",
          attrs: {},
          model: [
            { type: 'selection', clickToggle: true, },
            {
              key: 'warehouseId', label: 'label_warehouse', align: 'left',  'width': 150,
              attrs: {
                formatter: (r, c, v, i) => this.$formatNameCode(this.allWarehouseMap[v].name, this.allWarehouseMap[v].code)
              }
            },
            {
              key: 'customerCode', label: 'label_customer_info', align: 'left', 'width': 150,
              attrs: {
                formatter: (r, c, v, i) => this.$formatNameCode(r.customerName, r.customerCode)
              }
            },
            {
              key: 'skuOnlyCode', label: 'label_sku_only_code', align: 'left', 'min-width': 160,
              attrs: {
                formatter: (r, c, v, i) => r.skuId < 0 ? "——" : v
              }
            },
            {
              key: 'skuBarcode', label: 'label_sku_code', align: 'left','width': 160,
              attrs: {
                formatter: (r, c, v, i) => r.skuId < 0 ? "——" : v
              }
            },
            {
              key: 'skuName', label: 'label_sku_name', align: 'left', 'width': 160,
              attrs: {
                formatter: (r, c, v, i) => r.skuId < 0 ? "——" : v
              }
            },
            {
              key: 'skuNameEn', label: 'label_sku_name_en', align: 'left', 'width': 160,
              attrs: {
                formatter: (r, c, v, i) => r.skuId < 0 ? "——" : v
              }
            },
            {
              key: 'allotPutawayQyt', label: 'label_dure_journey_count', 'width': 100,
            },
            {
              key: 'needPutawayQyt', label: 'label_wait_put_count', 'width': 100,
            },
            {
              key: 'needOutboudQty', label: 'label_wait_outbound_count', 'width': 100,
            },

            // TOC 数量字段
            {
              key: 'tcLockQty', label: 'label_toc_lock_count', align: 'right','width': 100,
            },
            {
              key: 'tcUsableQty', label: 'label_toc_usable_count', align: 'right','width': 100,
            },
            // {
            //   key: 'tcFreezeQty', label: 'label_toc_frozen_count',
            // },

            // TOB 数量字段
            {
              key: 'tbLockQty', label: 'label_tob_lock_count', align: 'right','width': 100,
            },
            {
              key: 'tbUsableQty', label: 'label_tob_usable_count', align: 'right','width': 100,
            },
            // {
            //   key: 'tbFreezeQty', label: 'label_tob_frozen_count',
            // },

            // {
            //   key: 'destroyQty', label: 'label_abnormal_stock',
            // },

            {
              key: 'totalQty', label: 'label_usable_count', align: 'right','width': 100,  // 可用数量（良品/不良品
              attrs: {
                formatter: (r, c, v, i) => (r.goodUsableQty + r.badUsableQty) // + '/' + r.goodUsableQty + '/' + r.badUsableQty
              }
            },
            // {
            //   key: 'totalQty', label: 'label_lock_count', // （良品/不良品）
            //   attrs: {
            //     formatter: (r, c, v, i) => (r.goodLockQty + r.badLockQty)  // + '/' + r.goodLockQty + '/' + r.badLockQty
            //   }
            // },
            // {
            //   key: 'totalQty', label: 'label_frozen_count', // 冻结数量（良品/不良品）
            //   attrs: {
            //     formatter: (r, c, v, i) => (r.goodFreezeQty + r.badFreezeQty) // + '/' + r.goodFreezeQty + '/' + r.badFreezeQty
            //   }
            // },
            {
              key: 'totalQty', label: 'label_sum_stock', align: 'right','width': 100,
            },
            {
              type: 'operate', width: 160, fixed: 'right', operate: [

                {
                  label: 'label_view_detail', click: (row) => {
                    this.chooseRow = row
                    this.dialogVisible = true
                  }
                }

              ],
            }
          ],

        },

      },
      tableOption: {
        model: [
          {
            key: 'locationCode',
            label: 'label_warehouse_location_code',
            'min-width': 140,
            'show-overflow-tooltip': true,
          },
          { key: 'subContainerCode', label: 'label_container_code', 'min-width': 140, 'show-overflow-tooltip': true, },
          {
            key: 'bizType', label: 'label_business_type', 'width': 120, 'show-overflow-tooltip': true,
            formatter: (r, c, v, i) => this.$enumShow(v, "BizTypeEnum")
          },
          {
            key: 'stockKind',
            label: 'label_stock_quality',
            'width': 120,
            'show-overflow-tooltip': true,
            formatter: (r, c, v) => this.$enumShow(v, 'StockKindEnum')
          },

          { key: 'freezeQty', label: 'label_frozen_count', 'width': 120, 'show-overflow-tooltip': true, },

          { key: 'lockQty', label: 'label_lock_count', 'width': 120, 'show-overflow-tooltip': true, },
          { key: 'usableQty', label: 'label_usable_count', 'width': 120, 'show-overflow-tooltip': true, },

          { key: 'totalQty', label: 'label_container_inner_sum_count', 'width': 120, 'show-overflow-tooltip': true, },
          { key: 'putawayOrderNo', label: 'label_putaway_code', 'width': 120, 'show-overflow-tooltip': true, },
          {
            key: 'putawayTime',
            label: 'label_putaway_time',
            'width': 130,
            'show-overflow-tooltip': true,
            formatter: (r, c, v) => this.$dateFormat(v)
          },


        ]
      },

    };
  },
  computed: {
    ...mapState({ allWarehouseMap: state => state.allWarehouseMap }),
  },
  methods: {
    exportExcel() {
      const searchParams = this.$refs.SuperTablePage.getSearchFormData()
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: searchParams,
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              stockHeadIdList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: this.$url['oms/stock/exportExcel'],
            data: params,
          })
        }
      })

    },
    downloadImportTemp() {
      if (this.$clickFast()) return
      this.$downloadFile({
        loading: true,
        url: this.$url['oms/stock/downloadImportTemp']
      })

    },
    uploadFile(files) {
      this.$uploadFile({
        loading: true,
        url: this.$url['oms/stock/importExcel'],
        file: files[0],
        success: (res) => {
          this.$emitPage("oms>import_manage", 'reload')
          this.$confirm(this.$tt("tip_importing_confirm_goto_recode_list"), this.$tt('label_tip'), {
            type: 'success'
          }).then(() => {
            this.$router.push({
              path: '/page/oms/report/import_manage',
            });
          }).catch(() => {
          });
        }
      })
    },
  }
};

</script>
<style></style>
